package com.colin.app.activity.coordinator;

import android.os.Bundle;

import com.colin.app.app.AppActivity;
import com.colin.app.app.BasePresenterImpl;
import com.colin.app.bean.DemoBean;
import com.colin.app.fragment.example.ExampleFragment;

/**
 * Created by Colin on 2017/1/15.
 */

public class CoordinatorTabLayoutPresenterImpl extends BasePresenterImpl implements CoordinatorTabLayoutContract.CoordinatorTabLayoutPresenter {

    private CoordinatorTabLayoutContract.CoordinatorTabLayoutView mCoordinatorTabLayoutView;
    private CoordinatorTabLayoutContract.CoordinatorTabLayoutModel mCoordinatorTabLayoutModel;

    public CoordinatorTabLayoutPresenterImpl(AppActivity mAppActivity, CoordinatorTabLayoutContract.CoordinatorTabLayoutView mCoordinatorTabLayoutView) {
        super(mAppActivity, mCoordinatorTabLayoutView);
        this.mCoordinatorTabLayoutView = mCoordinatorTabLayoutView;
        this.mCoordinatorTabLayoutModel = new CoordinatorTabLayoutModelImpl();
    }

    @Override
    public void initViewPager() {
        mCoordinatorTabLayoutView.initViewPager(mCoordinatorTabLayoutModel.getFragmentList(mAppActivity), mCoordinatorTabLayoutModel.getFragmentIDList(), mCoordinatorTabLayoutModel.getFragmentTitleList());
    }

    @Override
    public void initCoordinatorTabLayout() {
        mCoordinatorTabLayoutView.initCoordinatorTabLayout(mCoordinatorTabLayoutModel.getImageHead(), mCoordinatorTabLayoutModel.getColorArray(mAppActivity));
    }

    @Override
    public void clickItem(DemoBean demoBean) {
        Bundle bundle = new Bundle();
        bundle.putParcelable("clazz", demoBean);
        mCoordinatorTabLayoutView.startActivity(demoBean.getTarget(), bundle, false);
    }

    @Override
    public void setLayoutType(int layoutType) {
        if (mCoordinatorTabLayoutModel.getLayoutType() != layoutType) {
            mCoordinatorTabLayoutModel.setLayoutType(layoutType);
            for (ExampleFragment exampleFragment : mCoordinatorTabLayoutModel.getFragmentList(mAppActivity)) {
                if (null != exampleFragment) {
                    exampleFragment.setLayoutType(layoutType);
                }
            }
        }
    }
}
